package com.qinsoft.business.user.dao;

import org.apache.ibatis.session.SqlSession;

import com.qinsoft.business.user.bean.User;
import com.qinsoft.frame.messages.WriteMessage;
import com.qinsoft.frame.utils.DbUtil;

public class UserDao {

	public static void keep(User user)
	{
		SqlSession sqlMap = null;
        try 
        {
            sqlMap= DbUtil.getSqlMapClient();
        	sqlMap.insert("com.qinsoft.business.user.sqlMap.user.insert",user);            	
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog("com.qinsoft.business.user.dao.UserDao.keep("+ user.getNick() +")", e);
        }
        finally
        {
            sqlMap.close();
        }
	}
	
	public static User getUser(String nick)
	{
	    SqlSession sqlMap = null;
	    User user = null;
        try 
        {
            sqlMap= DbUtil.getSqlMapClient();
            user = sqlMap.selectOne("com.qinsoft.business.user.sqlMap.user.select",nick); 
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog("com.qinsoft.business.user.dao.UserDao.getUser("+ nick +")", e);
        }
        finally
        {
            sqlMap.close();
        }
        return user;
	}
	
	public static void delete()
	{
	    SqlSession sqlMap = null;
        try 
        {
            sqlMap= DbUtil.getSqlMapClient();
            sqlMap.delete("com.qinsoft.business.user.sqlMap.user.delete"); 
        }
        catch (Exception e) 
        {
            WriteMessage.WriteErrorLog("com.qinsoft.business.user.dao.UserDao.delete()", e);
        }
        finally
        {
            sqlMap.close();
        }
	}
}
